package com.asion.qkan.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.asion.qkan.R;
import com.asion.qkan.ui.util.ToastUtil;
import com.asion.qkan.ui.view.BaseActivity;

import butterknife.BindView;

public class LoginActivity extends BaseActivity {

    @BindView(R.id.login_toolbar)
    Toolbar loginToolbar;
    @BindView(R.id.login_username)
    EditText loginUsername;
    @BindView(R.id.login_password)
    EditText loginPassword;
    @BindView(R.id.login_register)
    Button loginRegister;
    @BindView(R.id.login_login)
    Button loginLogin;
    @BindView(R.id.login_qq)
    TextView loginQq;
    @BindView(R.id.login_wechat)
    TextView loginWechat;
    @BindView(R.id.login_image)
    ImageView loginImage;

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {

    }

    public static void startAction(Activity activity){
        Intent intent = new Intent(activity, LoginActivity.class);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.fade_in,
                R.anim.fade_out);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(loginToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        loginRegister.setOnClickListener(v-> ToastUtil.showShort("去注册"));
        loginLogin.setOnClickListener(v -> ToastUtil.showShort("去登陆"));
        loginQq.setOnClickListener(v -> ToastUtil.showShort("QQ登录"));
        loginWechat.setOnClickListener(v -> ToastUtil.showShort("微信登录"));

        loginPassword.setOnFocusChangeListener((v,focused) -> {
            if(focused){
                loginImage.setImageResource(R.drawable.ic_login_invisible);
            }else{
                loginImage.setImageResource(R.drawable.ic_login_visible);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.login_forget,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;

            case R.id.login_forget:
                ToastUtil.showShort("跳找回密码界面");
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        finish();
    }
}
